package com.lichuandi.service;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

// 使用策略
@Service
public class OrderService {
//    @Autowired
    @Resource
    private Map<String, DiscountStrategy> discountStrategy; // Spring自动注入所有DiscountStrategy实现

    // 根据策略名称计算折扣后的金额
    public double calculateTotal(String strategyName, double amount) {
        DiscountStrategy strategy = discountStrategy.get(strategyName);
        if (strategy != null) {
            return strategy.applyDiscount(amount);
        }
        return amount;
    }
}